var WPMT_DoctorEvaluation_ORM = /** @class */ (function () {
    function WPMT_DoctorEvaluation_ORM(workid) {
        this.data = {
            dbConn: TSLobsterAPI.Program.GetDbConn(),
            WorkId: 1
        };
        this.WPMT_DoctorEvaluation = {
            "model": {
                "ID": 0,
                "RecordId": 0,
                "OrderNo": "",
                "MPUserId": "",
                "EmpId": 0,
                "PatientId": 0,
                "Satisfaction": "",
                "EvaluateContent": "",
                "Status": 0,
                "EvaluateTime": "yyyy-MM-dd",
                "OperateTime": "yyyy-MM-dd",
                "WorkId": 0,
                "ReplyContent": "",
                "ReplyTime": "yyyy-MM-dd",
                "ReplyEmpId": 0,
                "DocName": "",
                "PatName": ""
            },
            "tablename": "WPMT_DoctorEvaluation",
            "key": "ID",
            "val": "0",
            "objval": {},
            "query": {},
            "where": "",
            "pageinfo": {},
            "WorkId": 1
        };
        this.data.WorkId = workid;
        this.WPMT_DoctorEvaluation.WorkId = workid;
    }
    WPMT_DoctorEvaluation_ORM.prototype.Save = function (model) {
        this.WPMT_DoctorEvaluation.objval = model;
        return TSLobsterAPI.DbHelper.SaveModel(this.data.dbConn, this.WPMT_DoctorEvaluation);
    };
    WPMT_DoctorEvaluation_ORM.prototype.GetList = function (where) {
        return TSLobsterAPI.OrmMsSql.GetListModel(this.data.dbConn, this.WPMT_DoctorEvaluation);
    };
    return WPMT_DoctorEvaluation_ORM;
}());

//author:kakake

//author:kakake
var tsschedualDao = /** @class */ (function () {
    function tsschedualDao(workid) {
        this.data = {
            dbConn: TSLobsterAPI.Program.GetDbConn(),
            WorkId: 1
        };
        this.data.WorkId = workid;
    }
    /**
     * 获取科室
     */
    tsschedualDao.prototype.getselectdept = function () {
        var strsql = 'select DeptId,Name from wpmt_basedept where delflag=0 and workid=@workid';
        return TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, { workid: this.data.WorkId });
    };
    /**
    * 获取医生列表
    */
    tsschedualDao.prototype.gettabledoctor = function (deptId, status, keyword, pageInfo) {
        var strsql = 'select * from wpmt_doctor where workid=@workid and empname like @keyword ';
        if (deptId > 0) {
            strsql += ' and deptid=@deptid';
        }
        //已出诊
        if (status == 1) {
            strsql += ' and (select COUNT(*) from wpmt_docschedual where workid=wpmt_doctor.workid and  doctid=wpmt_doctor.empid and schedualdate>GETDATE())>0';
        } //未出诊
        else if (status == 2) {
            strsql += ' and (select COUNT(*) from wpmt_docschedual where workid=wpmt_doctor.workid and  doctid=wpmt_doctor.empid and schedualdate>GETDATE())=0';
        }
        var dbparam = {
            workid: this.data.WorkId,
            deptid: deptId,
            keyword: '%' + keyword + '%'
        };
        return TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, dbparam, pageInfo);
    };
    /**
     * 获取
     */
    tsschedualDao.prototype.gettableschedual = function (SchedType, doctId, sdate, edate, pageInfo) {
        var strsql = 'select * from WPMT_DocSchedual where workid=@workid and SchedType=@SchedType and DoctID=@doctId and SchedualDate >= @sdate and SchedualDate <=@edate';
        var dbparam = {
            workid: this.data.WorkId,
            doctId: doctId,
            sdate: sdate,
            edate: edate,
            SchedType: SchedType
        };
        return TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, dbparam, pageInfo);
    };
    /**
     * 停用、启用
     */
    tsschedualDao.prototype.stopschedual = function (schedId, flag) {
        var strsql = 'update WPMT_DocSchedual set Flag=@flag where SchedualID=@schedId';
        TSLobsterAPI.DbHelper.DbExecuteUpdate(this.data.dbConn, strsql, { schedId: schedId, flag: flag });
    };
    tsschedualDao.prototype.setdoctorprice = function (Id, RegPrice, IHPrice) {
        var strsql = 'update WPMT_Doctor set RegPrice=@RegPrice,IHPrice=@IHPrice where Id=@Id';
        TSLobsterAPI.DbHelper.DbExecuteUpdate(this.data.dbConn, strsql, { Id: Id, RegPrice: RegPrice, IHPrice: IHPrice });
    };
    return tsschedualDao;
}());

//author:kakake
/**
 * 医生排班
 */
var tsschedualController = /** @class */ (function () {
    function tsschedualController() {
        this.data = {
            dbConn: TSLobsterAPI.Program.GetDbConn(),
            WorkId: 1
        };
        this.data.WorkId = TSLobsterAPI.Program.GetWorkId();
        this.service = new tsschedualService(this.data.WorkId);
        this.dao = new tsschedualDao(this.data.WorkId);
    }
    /**
     * 获取下拉框科室列表
     */
    tsschedualController.prototype.getselectdept = function () {
        var data = this.dao.getselectdept();
        return { selectdata: data };
    };
    /**
     * 获取医生列表
     */
    tsschedualController.prototype.gettabledoctor = function () {
        var pageInfo = {
            key: "Id",
            page: TSLobsterAPI.Program.RequestQuery("page", "1"),
            perPage: TSLobsterAPI.Program.RequestQuery("limit", "10"),
            totalRecord: 100
        };
        var deptId = TSLobsterAPI.Program.RequestQuery('deptId');
        var status = TSLobsterAPI.Program.RequestQuery('status');
        var keyword = TSLobsterAPI.Program.RequestQuery('keyword') || '';
        var data = this.dao.gettabledoctor(deptId, status, keyword, pageInfo);
        return { data: data, count: pageInfo.totalRecord };
    };
    /**
     * 生成排班
     */
    tsschedualController.prototype.generateschedual = function () {
        var model = JSON.parse(TSLobsterAPI.Program.RequestBody());
        return this.service.generateschedual(model);
    };
    tsschedualController.prototype.gettableschedual = function () {
        var pageInfo = {
            key: "SchedualID",
            page: TSLobsterAPI.Program.RequestQuery("page", "1"),
            perPage: TSLobsterAPI.Program.RequestQuery("limit", "10"),
            totalRecord: 100
        };
        var SchedType = TSLobsterAPI.Program.RequestQuery('SchedType');
        var doctId = TSLobsterAPI.Program.RequestQuery('doctId');
        var sdate = TSLobsterAPI.Program.RequestQuery('sdate');
        var edate = TSLobsterAPI.Program.RequestQuery('edate');
        var data = this.dao.gettableschedual(SchedType, doctId, sdate, edate, pageInfo);
        return { data: data, count: pageInfo.totalRecord };
    };
    tsschedualController.prototype.stopschedual = function () {
        var schedId = TSLobsterAPI.Program.RequestQuery('schedId');
        var flag = TSLobsterAPI.Program.RequestQuery('flag');
        this.dao.stopschedual(schedId, flag);
        return { result: true };
    };
    tsschedualController.prototype.setdoctorprice = function () {
        var model = JSON.parse(TSLobsterAPI.Program.RequestBody());
        this.dao.setdoctorprice(model.Id, model.RegPrice, model.IHPrice);
        return { result: true };
    };
    return tsschedualController;
}());

//author:kakake
var tsschedualService = /** @class */ (function () {
    function tsschedualService(workid) {
        this.data = {
            dbConn: TSLobsterAPI.Program.GetDbConn(),
            WorkId: 1
        };
        this.data.WorkId = workid;
    }
    /**
     * 计算两个日期，返回日期数组
     */
    tsschedualService.prototype.calculationdate = function (sdate, edate) {
        var datelist = [];
        var date1 = new Date(sdate);
        var date2 = new Date(edate);
        //calculate time difference
        var time_difference = date2.getTime() - date1.getTime();
        //calculate days difference by dividing total milliseconds in a day
        var days_difference = time_difference / (1000 * 60 * 60 * 24);
        datelist.push(sdate);
        for (var i = 1; i <= days_difference; i++) {
            var dateTime = new Date(sdate);
            var mdate = new Date(dateTime.setDate(dateTime.getDate() + i));
            datelist.push(TSLobsterAPI.Utils.dateFormat(mdate, 'yyyy-MM-dd'));
        }
        return datelist;
    };
    /**
     * 判断是否已排班
     */
    tsschedualService.prototype.existschedual = function (date, deptid, doctid, timerange, schedtype) {
        var strsql = 'select count(1) from WPMT_DocSchedual where SchedType=@schedtype and SchedualDate=@date and DeptId=@deptid and DoctID=@doctid and TimeRange=@timerange and WorkId=@workid';
        var dbparam = {
            date: date,
            deptid: deptid,
            doctid: doctid,
            timerange: timerange,
            schedtype: schedtype,
            workid: this.data.WorkId
        };
        return TSLobsterAPI.DbHelper.DbExecuteQuery(this.data.dbConn, strsql, dbparam) > 0;
    };
    tsschedualService.prototype.generateschedual = function (model) {
        var _this = this;
        var datelist = this.calculationdate(model.sdate, model.edate);
        var docschedual_orm = new WPMT_DocSchedual_ORM(this.data.WorkId);
        datelist.forEach(function (item) {
            //上午
            if (model.am_num > 0) {
                var docschedual = {};
                docschedual.SchedualID = 0;
                docschedual.DeptID = model.deptId;
                docschedual.DoctID = model.doctId;
                docschedual.SchedualDate = item;
                docschedual.TimeRange = 1;
                docschedual.Flag = 0;
                docschedual.AppointNum = model.am_num;
                docschedual.LimitNum = model.am_num;
                docschedual.RoomID = 0;
                docschedual.SchedType = model.SchedType;
                if (_this.existschedual(item, docschedual.DeptID, docschedual.DoctID, docschedual.TimeRange, docschedual.SchedType) == false) {
                    docschedual_orm.Save(docschedual);
                }
            }
            //下午
            if (model.pm_num > 0) {
                var docschedual = {};
                docschedual.SchedualID = 0;
                docschedual.DeptID = model.deptId;
                docschedual.DoctID = model.doctId;
                docschedual.SchedualDate = item;
                docschedual.TimeRange = 2;
                docschedual.Flag = 0;
                docschedual.AppointNum = model.pm_num;
                docschedual.LimitNum = model.pm_num;
                docschedual.RoomID = 0;
                docschedual.SchedType = model.SchedType;
                if (_this.existschedual(item, docschedual.DeptID, docschedual.DoctID, docschedual.TimeRange, docschedual.SchedType) == false) {
                    docschedual_orm.Save(docschedual);
                }
            }
            //晚上
            if (model.nm_num > 0) {
                var docschedual = {};
                docschedual.SchedualID = 0;
                docschedual.DeptID = model.deptId;
                docschedual.DoctID = model.doctId;
                docschedual.SchedualDate = item;
                docschedual.TimeRange = 3;
                docschedual.Flag = 0;
                docschedual.AppointNum = model.nm_num;
                docschedual.LimitNum = model.nm_num;
                docschedual.RoomID = 0;
                docschedual.SchedType = model.SchedType;
                if (_this.existschedual(item, docschedual.DeptID, docschedual.DoctID, docschedual.TimeRange, docschedual.SchedType) == false) {
                    docschedual_orm.Save(docschedual);
                }
            }
        });
        return { result: true };
    };
    return tsschedualService;
}());
var WPMT_DocSchedual_ORM = /** @class */ (function () {
    function WPMT_DocSchedual_ORM(workid) {
        this.data = {
            dbConn: TSLobsterAPI.Program.GetDbConn(),
            WorkId: 1
        };
        this.WPMT_DocSchedual = {
            "model": {
                "SchedualID": 0,
                "DeptID": 0,
                "DoctID": 0,
                "SchedualDate": "yyyy-MM-dd",
                "TimeRange": 0,
                "Flag": 0,
                "AppointNum": 0,
                "LimitNum": 0,
                "RoomID": 0,
                "WorkId": 0,
                "SchedType": 0
            },
            "tablename": "WPMT_DocSchedual",
            "key": "SchedualID",
            "val": "0",
            "objval": {},
            "query": {},
            "where": "",
            "pageinfo": {},
            "WorkId": 1
        };
        this.data.WorkId = workid;
        this.WPMT_DocSchedual.WorkId = workid;
    }
    WPMT_DocSchedual_ORM.prototype.Save = function (model) {
        this.WPMT_DocSchedual.objval = model;
        return TSLobsterAPI.DbHelper.SaveModel(this.data.dbConn, this.WPMT_DocSchedual);
    };
    WPMT_DocSchedual_ORM.prototype.GetList = function (where) {
        return TSLobsterAPI.OrmMsSql.GetListModel(this.data.dbConn, this.WPMT_DocSchedual);
    };
    return WPMT_DocSchedual_ORM;
}());

